package com.xdf.imoocdatav.service;

import com.xdf.imoocdatav.dao.cloud.DatavSec2Mapper;
import com.xdf.imoocdatav.model.DatavSec2;
import com.xdf.imoocdatav.utils.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DatavSec2ServiceImpl implements DatavSec2Service {

    @Autowired
    private DatavSec2Mapper dao;

    @Override
    public List<DatavSec2> selectAll() {
        List<DatavSec2> list = dao.selectAll();
        if( list.size()<=0 ) throw new BusinessException("没有从表 datav_sec2 获取到数据");
        String orderFullYear = list.get(0).getOrderFullYear();
        if( orderFullYear == null || "".equals(orderFullYear) || orderFullYear.length()<=0 )
            throw new BusinessException("未能获取到 orderFullYear 的值");

        String orderFullYearAxis = list.get(0).getOrderFullYearAxis();
        if( orderFullYearAxis == null || "".equals(orderFullYearAxis) || orderFullYearAxis.length()<=0 )
            throw new BusinessException("未能获取到 orderFullYearAxis 的值");

        String orderRank = list.get(0).getOrderRank();
        if( orderRank == null || "".equals(orderRank) || orderRank.length()<=0 )
            throw new BusinessException("未能获取到 orderRank 的值");

        String userFullYear = list.get(0).getUserFullYear();
        if( userFullYear == null || "".equals(userFullYear) || userFullYear.length()<=0 )
            throw new BusinessException("未能获取到 userFullYear 的值");

        String userFullYearAxis = list.get(0).getUserFullYearAxis();
        if( userFullYearAxis == null || "".equals(userFullYearAxis) || userFullYearAxis.length()<=0 )
            throw new BusinessException("未能获取到 userFullYearAxis 的值");

        String userRank = list.get(0).getUserRank();
        if( userRank == null || "".equals(userRank) || userRank.length()<=0 )
            throw new BusinessException("未能获取到 userRank 的值");

        String[] orderFullYears = orderFullYear.split(",");
        String[] orderFullYearAxises = orderFullYearAxis.split(",");
        String[] orderRanks = orderRank.split(",");
        String[] userFullYears = userFullYear.split(",");
        String[] userFullYearAxises = userFullYearAxis.split(",");
        String[] userRanks = userRank.split(",");

        list.get(0).setOrderFullYears(orderFullYears);
        list.get(0).setOrderFullYearAxises(orderFullYearAxises);
        list.get(0).setOrderRanks(orderRanks);
        list.get(0).setUserFullYears(userFullYears);
        list.get(0).setUserFullYearAxises(userFullYearAxises);
        list.get(0).setUserRanks(userRanks);
        return list;
    }
}
